home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / pdxpp.zip / PDXPP.H next >
C/C++ Source or Header  |  1990-06-28  |  15KB  |  535 lines

  1. //************************************************************
  2. // PDXPP.H -- Header file for Paradox Engine Class Library
  3. //
  4. //    Gary B. Weinfurther, 06/27/90
  5. //      Last revision:   06/28/90
  6. //************************************************************
  7.  
  8. #include <pxengine.h>
  9.  
  10. /***********************************************************
  11. // PXOBJ class -- Abstract base class for other PX classes.
  12. ************************************************************/
  13.  
  14. class PXOBJ
  15.     {
  16.     protected:
  17.         TABLEHANDLE tblHandle;    // Table handle
  18.         int pxerr;                // Error code
  19.  
  20.     public:
  21.         TABLEHANDLE TblHandle() {return(tblHandle);}
  22.         int Result()    {return pxerr;}
  23.         char *ErrMsg()    {return PXErrMsg(pxerr);}
  24.         operator void*(){return (void *)(pxerr == PXSUCCESS);}    // 0 if failed
  25.         operator!()        {return (pxerr != PXSUCCESS);}    // non-0 if failed
  26.     };
  27.  
  28. /******************************************************
  29. // PXTABLE class
  30. *******************************************************/
  31.  
  32. class PXTABLE : public PXOBJ
  33.     {
  34.     public:
  35.         PXTABLE(char *name, int index = 0, int saveEveryChange = FALSE)
  36.             {pxerr = PXTblOpen(name, &tblHandle, index, saveEveryChange);}
  37.  
  38.         PXTABLE(char *name, int nFlds, char **fldnames, char **types, int saveEvery = FALSE);
  39.  
  40.         ~PXTABLE() {pxerr = PXTblClose(tblHandle);}
  41.  
  42.         int Name(int bufSize, char *s)
  43.             {return(pxerr = PXTblName(tblHandle, bufSize, s));}
  44.  
  45.         RECORDNUMBER NRecs();
  46.         int NFlds();
  47.         int KeyNFlds();
  48.         int RecLocked(void);
  49.         int Changed();
  50.  
  51.         int Lock(int lockType)
  52.             {return(pxerr = PXNetTblLock(tblHandle, lockType));}
  53.         int Unlock(int lockType)
  54.             {return(pxerr = PXNetTblUnlock(tblHandle, lockType));}
  55.  
  56.         int Refresh()    {return(pxerr = PXNetTblRefresh(tblHandle));}
  57.         int RecDelete()    {return(pxerr = PXRecDelete(tblHandle));}
  58.         int First()        {return(pxerr = PXRecFirst(tblHandle));}
  59.         int Last()        {return(pxerr = PXRecLast(tblHandle));}
  60.         int Next()        {return(pxerr = PXRecNext(tblHandle));}
  61.         int Prev()        {return(pxerr = PXRecPrev(tblHandle));}
  62.  
  63.         RECORDNUMBER RecNum();
  64.         int RecGoto(RECORDNUMBER rn)
  65.             {return(pxerr = PXRecGoto(tblHandle, rn));}
  66.     };
  67.  
  68. /******************************************************
  69. // PXTABLE() -- Connstructor to CREATE a table.
  70. *******************************************************/
  71.  
  72. inline PXTABLE::PXTABLE(char *name, int nFlds, char **fldnames, char **types,
  73.                             int saveEvery)
  74. {
  75.     pxerr = PXTblCreate(name, nFlds, fldnames, types);
  76.     if(pxerr == PXSUCCESS)
  77.         pxerr = PXTblOpen(name, &tblHandle, 0, saveEvery);
  78. }
  79.  
  80. /******************************************************
  81. // NRecs() -- Returns the number of records in the table.
  82. *******************************************************/
  83.  
  84. inline RECORDNUMBER PXTABLE::NRecs()
  85. {
  86.     RECORDNUMBER recnum;
  87.  
  88.     pxerr = PXTblNRecs(tblHandle, &recnum);
  89.     return(recnum);
  90. }
  91.  
  92. /******************************************************
  93. // NFlds() -- Returns the number of fields in the table.
  94. *******************************************************/
  95.  
  96. inline int PXTABLE::NFlds()
  97. {
  98.     int n;
  99.  
  100.     pxerr = PXRecNFlds(tblHandle, &n);
  101.     return(n);
  102. }
  103.  
  104. /***************************************************************
  105. // KeyNFlds() -- Returns the number of key fields in the table.
  106. ****************************************************************/
  107.  
  108. inline int PXTABLE::KeyNFlds()
  109. {
  110.     int n;
  111.  
  112.     pxerr = PXKeyNFlds(tblHandle, &n);
  113.     return(n);
  114. }
  115.  
  116. /********************************************************************
  117. // RecLocked() -- Tests if the current record in the table is locked.
  118. *********************************************************************/
  119.  
  120. inline int PXTABLE::RecLocked()
  121. {
  122.     int locked;
  123.  
  124.     pxerr = PXNetRecLocked(tblHandle, &locked);
  125.     return(locked);
  126. }
  127.  
  128. /***************************************************************
  129. // Changed() -- Tests if a table has changed.
  130. ****************************************************************/
  131.  
  132. inline int PXTABLE::Changed()
  133. {
  134.     int changed;
  135.  
  136.     pxerr = PXNetTblChanged(tblHandle, &changed);
  137.     return(changed);
  138. }
  139.  
  140. /******************************************************
  141. // RecNum() -- Returns the current record number.
  142. *******************************************************/
  143.  
  144. inline RECORDNUMBER PXTABLE::RecNum()
  145. {
  146.     RECORDNUMBER recnum;
  147.  
  148.     pxerr = PXRecNum(tblHandle, &recnum);
  149.     return(recnum);
  150. }
  151.  
  152. /******************************************************
  153. // PXFIELD -- Class for Paradox fields.
  154. *******************************************************/
  155.  
  156. class PXFIELD : public PXOBJ
  157.     {
  158.     protected:
  159.         FIELDHANDLE handle;         // Field handle
  160.  
  161.     public:
  162.         PXFIELD(PXTABLE &pxtable, char *name);
  163.         PXFIELD(TABLEHANDLE th, char *name);
  164.         FIELDHANDLE FldHandle() {return(handle);}
  165.  
  166.         int FldName(int bufSize, char *s)
  167.             {return(pxerr = PXFldName(tblHandle, handle, bufSize, s));}
  168.  
  169.         int FldBlank();
  170.         int FldType(int bufSize, char *type)
  171.             {return(pxerr = PXFldType(tblHandle, handle, bufSize, type));}
  172.     };
  173.  
  174. /******************************************************
  175. // PXFIELD() -- Constructor for PXFIELD.
  176. *******************************************************/
  177.  
  178. inline PXFIELD::PXFIELD(PXTABLE &table, char *fname)
  179. {
  180.     tblHandle = table.TblHandle();
  181.     pxerr = PXFldHandle(tblHandle, fname, &handle);
  182. }
  183.  
  184. /******************************************************
  185. // PXFIELD() -- Constructor for PXFIELD.
  186. *******************************************************/
  187.  
  188. inline PXFIELD::PXFIELD(TABLEHANDLE th, char *fname)
  189. {
  190.     tblHandle = th;
  191.     pxerr = PXFldHandle(tblHandle, fname, &handle);
  192. }
  193.  
  194. /******************************************************
  195. // FldBlank() -- Returns non-zero if field is blank.
  196. *******************************************************/
  197.  
  198. inline int PXFIELD::FldBlank()
  199. {
  200.     int blank;
  201.  
  202.     pxerr = PXFldBlank(tblHandle, handle, &blank);
  203.     return(blank);
  204. }
  205.  
  206. /******************************************************
  207. // PXRECORD class
  208. *******************************************************/
  209.  
  210. class PXRECORD : public PXOBJ
  211.     {
  212.     protected:
  213.         RECORDHANDLE handle;
  214.  
  215.     public:
  216.         PXRECORD(PXTABLE &pxtable);
  217.         PXRECORD(TABLEHANDLE th);
  218.         PXRECORD(PXRECORD &sourcerec);
  219.         PXRECORD &operator=(PXRECORD &sourcerec);
  220.         ~PXRECORD() {pxerr = PXRecBufClose(handle);}
  221.  
  222.         RECORDHANDLE RecordHandle() {return(handle);}
  223.  
  224.         int NFlds(void);
  225.  
  226.         int Append() {return(pxerr = PXRecAppend(tblHandle,handle));}
  227.         int Update() {return(pxerr = PXRecUpdate(tblHandle,handle));}
  228.         int RecGet() {return(pxerr = PXRecGet(tblHandle,handle));}
  229.         int Insert() {return(pxerr = PXRecInsert(tblHandle,handle));}
  230.         int Empty()  {return(pxerr = PXRecBufEmpty(handle));}
  231.         int Delete() {return(pxerr = PXRecDelete(tblHandle));}
  232.  
  233.         RECORDNUMBER RecNum(void);
  234.         int Goto(RECORDNUMBER rn) {return(pxerr = PXRecGoto(tblHandle,rn));}
  235.  
  236.         int First();
  237.         int Last();
  238.         int Next();
  239.         int Prev();
  240.  
  241.         int SrchFld(PXFIELD &field, int scope = SEARCHFIRST)
  242.             {return SrchFld(field.FldHandle(), scope);}
  243.  
  244.         int SrchFld(FIELDHANDLE fh, int scope = SEARCHFIRST)
  245.             {return(pxerr = PXSrchFld(tblHandle, handle, fh, scope));}
  246.  
  247.         int SrchKey(int nFlds, int scope = SEARCHFIRST)
  248.             {return(pxerr = PXSrchKey(tblHandle, handle, nFlds, scope));}
  249.  
  250.         int Put(FIELDHANDLE fh)
  251.             {return(pxerr = PXPutBlank(handle, fh));}
  252.  
  253.         int Put(FIELDHANDLE fh, short s)
  254.             {return(pxerr = PXPutShort(handle, fh, s));}
  255.  
  256.         int Put(FIELDHANDLE fh, long l);
  257.         int Put(FIELDHANDLE fh, int month, int day, int year);
  258.  
  259.         int Put(FIELDHANDLE fh, double d)
  260.             {return(pxerr = PXPutDoub(handle, fh, d));}
  261.  
  262.         int Put(FIELDHANDLE fh, char *a)
  263.             {return(pxerr = PXPutAlpha(handle, fh, a));}
  264.  
  265.         int Put(PXFIELD &field)
  266.             {return Put(field.FldHandle());}
  267.  
  268.         int Put(PXFIELD &field, short s)
  269.             {return Put(field.FldHandle(), s);}
  270.  
  271.         int Put(PXFIELD &field, long l)
  272.             {return Put(field.FldHandle(), l);}
  273.  
  274.         int Put(PXFIELD &field, int month, int day, int year)
  275.             {return Put(field.FldHandle(), month, day, year);}
  276.  
  277.         int Put(PXFIELD &field, double d)
  278.             {return Put(field.FldHandle(), d);}
  279.  
  280.         int Put(PXFIELD &field, char *a)
  281.             {return Put(field.FldHandle(), a);}
  282.  
  283.         int Get(FIELDHANDLE fh, short &s)
  284.             {return (pxerr = PXGetShort(handle, fh, &s));}
  285.  
  286.         int Get(FIELDHANDLE fh, long &l);
  287.  
  288.         int Get(FIELDHANDLE fh, double &d)
  289.             {return (pxerr = PXGetDoub(handle, fh, &d));}
  290.  
  291.         int Get(FIELDHANDLE fh, int &m, int &d, int &y);
  292.  
  293.         int Get(FIELDHANDLE fh, int bufSize, char *a)
  294.             {return (pxerr = PXGetAlpha(handle, fh, bufSize, a));}
  295.  
  296.         int Get(PXFIELD &field, short &s)
  297.             {return Get(field.FldHandle(), s);}
  298.  
  299.         int Get(PXFIELD &field, long &l)
  300.             {return Get(field.FldHandle(), l);}
  301.  
  302.         int Get(PXFIELD &field, double &d)
  303.             {return Get(field.FldHandle(), d);}
  304.  
  305.         int Get(PXFIELD &field, int bufSize, char *a)
  306.             {return Get(field.FldHandle(), bufSize, a);}
  307.  
  308.         int Get(PXFIELD &field, int &m, int &d, int &y)
  309.             {return Get(field.FldHandle(), m, d, y);}
  310.  
  311.     };
  312.  
  313.  
  314. /******************************************************
  315. // PXRECORD() -- constructor for PXRECORD.
  316. *******************************************************/
  317.  
  318. inline PXRECORD::PXRECORD(PXTABLE &table)
  319. {
  320.     tblHandle = table.TblHandle();
  321.     pxerr = PXRecBufOpen(tblHandle, &handle);
  322. }
  323.  
  324. /******************************************************
  325. // PXRECORD() -- constructor for PXRECORD.
  326. *******************************************************/
  327.  
  328. inline PXRECORD::PXRECORD(TABLEHANDLE th)
  329. {
  330.     tblHandle = th;
  331.     pxerr = PXRecBufOpen(tblHandle, &handle);
  332. }
  333.  
  334. /******************************************************
  335. // PXRECORD() -- constructor for PXRECORD.
  336. *******************************************************/
  337.  
  338. inline PXRECORD::PXRECORD(PXRECORD &sourcerec)
  339. {
  340.     tblHandle = sourcerec.tblHandle;
  341.     pxerr = PXRecBufOpen(tblHandle, &handle);
  342.     if(pxerr == PXSUCCESS)
  343.         pxerr = PXRecBufCopy(sourcerec.handle, handle);
  344. }
  345.  
  346. /******************************************************
  347. // PXRECORD() -- constructor for PXRECORD.
  348. *******************************************************/
  349.  
  350. inline PXRECORD& PXRECORD::operator=(PXRECORD &sourcerec)
  351. {
  352.     pxerr = PXRecBufCopy(sourcerec.handle, handle);
  353.     return(*this);
  354. }
  355.  
  356. /******************************************************
  357. // NFlds() -- Returns the number of fields in the table.
  358. *******************************************************/
  359.  
  360. inline int PXRECORD::NFlds()
  361. {
  362.     int n;
  363.  
  364.     pxerr = PXRecNFlds(tblHandle, &n);
  365.     return(n);
  366. }
  367.  
  368. /******************************************************
  369. // RecNum() -- Returns the current record number.
  370. *******************************************************/
  371.  
  372. inline RECORDNUMBER PXRECORD::RecNum()
  373. {
  374.     RECORDNUMBER recnum;
  375.  
  376.     pxerr = PXRecNum(tblHandle, &recnum);
  377.     return(recnum);
  378. }
  379.  
  380. /******************************************************
  381. // First() -- Retrieves the first record in the table.
  382. *******************************************************/
  383.  
  384. inline int PXRECORD::First()
  385. {
  386.     pxerr = PXRecFirst(tblHandle);
  387.     if(pxerr == PXSUCCESS)
  388.         pxerr = PXRecGet(tblHandle, handle);
  389.  
  390.     return(pxerr);
  391. }
  392.  
  393. /******************************************************
  394. // Last() -- Retrieves the last record in the table.
  395. *******************************************************/
  396.  
  397. inline int PXRECORD::Last()
  398. {
  399.     pxerr = PXRecLast(tblHandle);
  400.     if(pxerr == PXSUCCESS)
  401.         pxerr = PXRecGet(tblHandle, handle);
  402.  
  403.     return(pxerr);
  404. }
  405.  
  406. /******************************************************
  407. // Next() -- Retrieves the next record in the table.
  408. *******************************************************/
  409.  
  410. inline int PXRECORD::Next()
  411. {
  412.     pxerr = PXRecNext(tblHandle);
  413.     if(pxerr == PXSUCCESS)
  414.         pxerr = PXRecGet(tblHandle, handle);
  415.  
  416.     return(pxerr);
  417. }
  418.  
  419. /******************************************************
  420. // Prev() -- Retrieves the previous record in the table.
  421. *******************************************************/
  422.  
  423. inline int PXRECORD::Prev()
  424. {
  425.     pxerr = PXRecPrev(tblHandle);
  426.     if(pxerr == PXSUCCESS)
  427.         pxerr = PXRecGet(tblHandle, handle);
  428.  
  429.     return(pxerr);
  430. }
  431.  
  432. /******************************************************
  433. // Put() -- Puts a date or long value into a field.
  434. *******************************************************/
  435.  
  436. inline int PXRECORD::Put(FIELDHANDLE fh, long l)
  437. {
  438.     char type[6];
  439.  
  440.     pxerr = PXFldType(tblHandle, fh, 6, type);
  441.     if(pxerr == PXSUCCESS)
  442.         pxerr = (type[0] == 'D') ? PXPutDate(handle, fh, l)
  443.                                  : PXPutLong(handle, fh, l);
  444.     return(pxerr);
  445. }
  446.  
  447. /******************************************************
  448. // Put() -- Puts an MDY date into a field.
  449. *******************************************************/
  450.  
  451. inline int PXRECORD::Put(FIELDHANDLE fh, int month, int day, int year)
  452. {
  453.     long date;
  454.  
  455.     pxerr = PXDateEncode(month, day, year, &date);
  456.     if(pxerr == PXSUCCESS)
  457.         pxerr = PXPutDate(handle, fh, date);
  458.  
  459.     return(pxerr);
  460. }
  461.  
  462. /******************************************************
  463. // Get() -- Gets a date or long value from a field.
  464. *******************************************************/
  465.  
  466. inline int PXRECORD::Get(FIELDHANDLE fh, long &l)
  467. {
  468.     char type[6];
  469.  
  470.     pxerr = PXFldType(tblHandle, fh, 6, type);
  471.     if(pxerr == PXSUCCESS)
  472.         pxerr = (type[0] == 'D') ? PXGetDate(handle, fh, &l)
  473.                                  : PXGetLong(handle, fh, &l);
  474.     return(pxerr);
  475. }
  476.  
  477. /******************************************************
  478. // Get() -- Gets an MDY date from a field.
  479. *******************************************************/
  480.  
  481. inline int PXRECORD::Get(FIELDHANDLE fh, int &month, int &day, int &year)
  482. {
  483.     long date;
  484.  
  485.     pxerr = PXGetDate(handle, fh, &date);
  486.     if(pxerr == PXSUCCESS)
  487.         pxerr = PXDateDecode(date, &month, &day, &year);
  488.  
  489.     return(pxerr);
  490. }
  491.  
  492.  
  493. /******************************************************
  494. // PXLOCK class
  495. *******************************************************/
  496.  
  497. class PXLOCK : public PXOBJ
  498.     {
  499.     protected:
  500.         LOCKHANDLE handle;
  501.  
  502.     public:
  503.         PXLOCK(PXTABLE &pxtable);
  504.         PXLOCK(PXRECORD &pxrecord);
  505.         ~PXLOCK()    {Unlock();}
  506.         int Unlock(){return(pxerr = PXNetRecUnlock(tblHandle, handle));}
  507.  
  508.         LOCKHANDLE LockHandle()    {return(handle);}
  509.         int Locked();
  510.  
  511.         int Goto()
  512.             {return(pxerr = PXNetRecGotoLock(tblHandle, handle));}
  513.     };
  514.  
  515. /******************************************************
  516. // PXLOCK() -- Constructor for PXLOCK class
  517. //            -- Locks the current record.
  518. *******************************************************/
  519.  
  520. inline PXLOCK::PXLOCK(PXTABLE &pxtable)
  521. {
  522.     tblHandle = pxtable.TblHandle();
  523.     pxerr = PXNetRecLock(tblHandle, &handle);
  524. }
  525.  
  526. /******************************************************
  527. // PXLOCK() -- Constructor for PXLOCK class
  528. //            -- Locks the current record.
  529. *******************************************************/
  530.  
  531. inline PXLOCK::PXLOCK(PXRECORD &pxrecord)
  532. {
  533.     tblHandle = pxrecord.TblHandle();
  534.     pxerr = PXNetRecLock(tblHandle, &handle);
  535. }